package com.android.publicModule.model.notification;

import com.android.publicModule.system.SystemInfo;
import com.muge.cartoon.naruto.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.RemoteViews;

public class NotificationManage {

	private Context mContext;
	private NotificationManager notificationManager = null;
	
	public NotificationManage(Context context) {
		mContext = context.getApplicationContext();
		notificationManager = (NotificationManager) mContext.getSystemService(Service.NOTIFICATION_SERVICE);
	}
	
	/**
	 * 创建下载进度条通知栏
	 * @param title
	 * @param content
	 * @return
	 */
	public Notification createDownloadProgressNotification(String title,String content,int percent) {
		Notification downloadNotif = new Notification();
		downloadNotif.tickerText = title;
		downloadNotif.icon = android.R.drawable.stat_sys_download;
		downloadNotif.contentView = new RemoteViews(SystemInfo.getPackageName(mContext),R.layout.notification_down);
		downloadNotif.contentView.setImageViewResource(R.id.notification_icon,android.R.drawable.stat_sys_download);
		downloadNotif.contentView.setTextViewText(R.id.notification_content,content);
		downloadNotif.contentView.setProgressBar(R.id.progressDialog_progressBar,100,percent,false);
        downloadNotif.contentView.setTextViewText(R.id.notification_percent,String.valueOf(percent)+"%");
        return downloadNotif;
	}
	
	
	public Notification createNotificationNews(String title,String content) {
		Notification downloadNotif = new Notification();
		downloadNotif.tickerText = title;
		downloadNotif.icon = R.drawable.icon;
		downloadNotif.contentView = new RemoteViews(SystemInfo.getPackageName(mContext),R.layout.notification_news);
		downloadNotif.contentView.setImageViewResource(R.id.notification_icon,R.drawable.icon);
		downloadNotif.contentView.setTextViewText(R.id.notification_title,title);
		if(content!=null&&content.length()>0)
		{
			downloadNotif.contentView.setTextViewText(R.id.notification_content,content);
			downloadNotif.contentView.setViewVisibility(R.id.notification_content, View.VISIBLE);
		}
		else
		{
			downloadNotif.contentView.setViewVisibility(R.id.notification_content, View.GONE);
		}
        return downloadNotif;
	}
	
	public Notification createNotificationImg(String title) {
		Notification downloadNotif = new Notification();
		downloadNotif.tickerText = title;
		downloadNotif.icon = R.drawable.icon;
		downloadNotif.contentView = new RemoteViews(SystemInfo.getPackageName(mContext),R.layout.notification_img);
		downloadNotif.contentView.setImageViewResource(R.id.notification_icon,R.drawable.icon);
        return downloadNotif;
	}
	
	public void setPendingIntent(Notification downloadNotif,int requestCode,Intent intent) {
		if(downloadNotif!=null)
		{
			PendingIntent pending = PendingIntent.getBroadcast(mContext, requestCode, intent,PendingIntent.FLAG_UPDATE_CURRENT);
			downloadNotif.contentIntent = pending;
		}
	}
	
	public void setDownloadProgress(Notification downloadNotif,int percent) {
		if(downloadNotif!=null)
		{
			if(downloadNotif.contentView!=null)
			{
				downloadNotif.contentView.setProgressBar(R.id.progressDialog_progressBar,100,percent,false);
				downloadNotif.contentView.setTextViewText(R.id.notification_percent,String.valueOf(percent)+"%");
			}
		}
	}
	
	public void setImageViewBitmap(Notification downloadNotif,Bitmap bitmap) {
		if(downloadNotif!=null)
		{
			if(downloadNotif.contentView!=null)
			{
				downloadNotif.contentView.setImageViewBitmap(R.id.notification_icon, bitmap);
			}
		}
	}
	
	public void notify(int id,Notification notification) {
		if(notificationManager!=null)
		{
			notificationManager.notify(id, notification);
		}
	}
	
	public void cancel(int id) {
		if(notificationManager!=null)
		{
			notificationManager.cancel(id);
		}
	}
	
}
